﻿using System.Diagnostics.Contracts;
using T4UtilityBelt.UxDesigns.Controls.Renderers.Windows;
using T4UtilityBelt.Writers;

namespace T4UtilityBelt.UxDesigns.Specialized.Renderers.WindowsPhone
{
    public class ActionButtonRenderer : ControlRenderer<ActionButton, IActionButtonRenderer>, IActionButtonRenderer
    {

        // <tcl:BindableApplicationBarIconButton IconUri="/images/appbar.save.rest.png" Text="Save" tcl:AppBarItemClick.Command="{Binding SaveCommand}" />

        protected override void OnRenderUiXmlBegin(ActionButton control, CodeWriter writer)
        {
            Contract.Assert(control != null);
            Contract.Assert(writer != null);

            writer.WriteBeginTag("tcl:BindableApplicationBarIconButton");

            if (!string.IsNullOrEmpty((control.IconUri)))
            {
                writer.WriteAttributeFormat("IconUri", "/images/{0}", control.IconUri);
            }
            writer.AddBinding("tcl:AppBarItemClick.Command", control.Click);
            writer.AddBinding("Text", control.Text);
            writer.WriteFullEnd();
        }

        protected override void OnRenderUiXmlContent(ActionButton control, CodeWriter writer)
        {
            Contract.Assert(control != null);
            Contract.Assert(writer != null);

        }

        protected override void OnRenderUiXmlEnd(ActionButton control, CodeWriter writer)
        {
            Contract.Assert(control != null);
            Contract.Assert(writer != null);
            
        }
    }
}